export function get(url, data) {
  return request(url, 'GET', data)
}
export function post(url, data) {
  console.log(data);
  console.log(url);
  return request(url, 'POST', data)
}

function request(url, method, data) {
  console.log(url, method, data);
  return new Promise((resolve, reject) => {
    uni.request({
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data,
      method,
      url: url,
      success: function (res) {
        if (res.statusCode === 200) {
          // console.log(res.data);
          if (res.data) {
            // console.log("000000");
            resolve(res.data)
          } else {
            // console.log(11);
            resolve(res.data)
          }

        } else {
          uni.showToast({
            title: "错误",
            icon: "none"
          })
          reject(res.data)
        }
      },
      complete: function (res) {
        // console.log("一直");
      },
      fail: function (res) {
        uni.showToast({
          title: "服务器错误",
          icon: "none"
        })
        // console.log(JSON.stringify(res));
      }
    })
  })
}
export function showModal(title, content) {
  uni.showModal({
    title,
    content,
    showCancel: false
  })
}
export function showSuccess(text) {
  uni.showToast({
    title: text,
    icon: 'success'
  })
}
